package com.ht.controller;




import cn.hutool.json.JSONUtil;
import com.ht.data.Result;
import com.ht.dto.Drug;
import com.ht.dto.User;
import com.ht.service.IDrugService;
import com.ht.util.JwtUtil;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 代齐园
 * @since 2022-05-28
 */
@RestController
@RequestMapping("/drug")
@Api(value = "预约药单的信息")
public class DrugController {
    @Autowired
    private IDrugService drugService;

    @GetMapping("/getDrug")
    @ApiOperation(value = "查询已预约的药单")
    @ApiImplicitParam(name = "token",value = "用户token",required = true,paramType = "header")
    public Result getDrug(@RequestHeader("AuthToken")String token ){
        Claims claims = new JwtUtil().parseJwt(token);
        User user = JSONUtil.toBean(claims.getSubject(), User.class);
        List<Drug> drugList = drugService.getDrug(user.getId());
        return Result.OK().setData(drugList);


    }
}
